package com.controller.infocenter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.MyCollectionInfo;
import com.po.RulePointInfo;
import com.service.infocenter.MyCollectionService;
import com.service.infocenter.RulePointService;

@Controller
@RequestMapping("/jsp/infocenter")
public class MyCollectionController {
	@Resource(name="myCollectionServiceImp")
    private MyCollectionService myCollectionService;
	@Resource(name="rulePointServiceImp")
    private RulePointService rulePointService;
	@RequestMapping(value="/getCollectionview")
	public String getCollectionview(){
		
		return "infocenter/mycollection";
	}	
	@ResponseBody
	@RequestMapping(value="/getCollection")
	public Map<String, Object> getCollection(int limit,int offset,String departmentname, HttpServletRequest request){
		String uploaduser = request.getSession().getAttribute("user_id").toString();
		MyCollectionInfo myCollectionInfo=new MyCollectionInfo();
		myCollectionInfo.setUser_id(uploaduser);
		myCollectionInfo.setName(departmentname);
		myCollectionInfo.setPage(offset);
		myCollectionInfo.setRows(limit);
		int count=myCollectionService.getMyCollectionCount(myCollectionInfo);
		List<MyCollectionInfo> list=myCollectionService.getMyCollectionList(myCollectionInfo);
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("total", count);
		map.put("rows", list);
		return map;
	}
	@ResponseBody
	@RequestMapping(value="/addCollection")
	public int addCollection(MyCollectionInfo myCollectionInfo, HttpServletRequest request, HttpServletResponse resp){
		String uploaduser = request.getSession().getAttribute("user_id").toString();
		myCollectionInfo.setUser_id(uploaduser);
		int i=myCollectionService.addMyCollection(myCollectionInfo);
		return i;
	}
	@ResponseBody
	@RequestMapping(value="/deleteCollection")
	public int deleteCollection(MyCollectionInfo myCollectionInfo, HttpServletRequest request, HttpServletResponse resp){
		String uploaduser = request.getSession().getAttribute("user_id").toString();
		myCollectionInfo.setUser_id(uploaduser);
		int i=myCollectionService.deleteMyCollection(myCollectionInfo);
		return i;
	}
	@ResponseBody
	@RequestMapping(value="/deleteCollections")
	public int deleteCollections(String ids){
		System.out.println(ids);
		String[] id = ids.split(",");
		int i=myCollectionService.deleteMyCollections(id);
		return i;
	}
	
	@RequestMapping(value="/getRulePointview")
	public String getRulePointview(){
		return "infocenter/point";
	}
	@ResponseBody
	@RequestMapping(value="/getRulePoint")
	public Map<String, Object> getRulePoint(int offset,int limit,String content){
		RulePointInfo rulePointInfo=new RulePointInfo();
		rulePointInfo.setRule_description(content);
		rulePointInfo.setPage(offset);
		rulePointInfo.setRows(limit);
		int count=rulePointService.getRulePointCount(rulePointInfo);
		List<RulePointInfo> list=rulePointService.getRulePointList(rulePointInfo);
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("total", count);
		map.put("rows", list);
		return map;
	}
}
